class Solution5zuichanghuiwenzichuan {
    public String longestPalindrome(String s) {
          if(s == null || s.length() == 0) return "" ; 
          int left = 0 , right = 0 ; 
          int len = s.length() ;
          char[] arr = s.toCharArray() ;
          boolean[][] dp = new boolean[len][len] ; 
          for(int i=len-1 ; i>=0  ; i --){
            for(int j=i ; j < len ; j ++){
                if(arr[i] == arr[j]){
                    if(i == j){
                        dp[i][j] = true ;
                    }else if(i+1 == j){
                        dp[i][j] = true ;
                    }else{
                        dp[i][j] = dp[i+1][j-1] ; 
                    }
                }else{
                    dp[i][j] = false ;
                }
                if(dp[i][j] && j-i > right -left){
                    left = i ;
                    right = j; 
                }
            }
          } 
         return s.substring(left , right+1) ; 
    }
}